require(['jquery', 'cookie', 'app', 'lay','base64'], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: [],
                th: {},
                ADD:{},
                User:{}
            }
            , created: function () {
                this.User=JSON.parse(getCookie("user"));
                this.loadPage()
            }
            , methods: {
                loadPage: function () {
                    var json = {};
                    json["APPID"] = "550e8400-e29b-41d4-a716-446655440000";
                    json["uuid"] = "1566381003884";
                    var re = playAjax("1574998957822", json);
                    var toolbar = [];
                    toolbar[0] = {
                        "clas": "",
                        "eve": "BAND",
                        "tit": "上架/下架",
                        "fnc": function (data) {
                            if (data.length == 0) {
                                alr("请选中一行！");
                                return false;
                            } else {
                                debugger;
                                if(data[0].f_status==1){
                                    data[0].f_status=0;
                                }else if(data[0].f_status==0){
                                    data[0].f_status=1;
                                }
                                loadT();
                                var re = playAjax("1574998957830", data[0]);
                                closeLoad();
                                alr(re.title);
                                setTimeout(function () {
                                    dic.referXadmin();
                                }, 1500);
                            }
                        }
                    };
                    toolbar[1] = {
                        "clas": "",
                        "eve": "UPDATE",
                        "tit": "修改",
                        "fnc": function (data) {
                            if (data.length == 0) {
                                alr("请选中一行！");
                                return false;
                            } else {
                                dic.th = data[0];
                                dic.th.f_text_img=Base64.decode(dic.th.f_text_img.replace(/ /g,"+"));
                                setTimeout(function () {
                                    editor1.txt.html("");
                                    editor1.txt.html(dic.th.f_text_img);
                                },800);
                                $("html,body").animate({scrollTop: $(".layui-tab-content").offset().top}, 500);
                                layui.use(['element'], function () {
                                    var element = layui.element;
                                    element.tabChange('docDemoTabBrief', '2');
                                });
                                $("#SCS").parent().html("<img style='width:80%' src='"+dic.th.f_shop_img+"'>");
                                setTimeout(function () {
                                    layui.use(['element'], function () {
                                        var form = layui.form;
                                        form.render();
                                    })
                                },1500);
                            }
                        }
                    };
                    if (re.code == '0') {
                        bspVIEW($(".sa-table"), "1566381003883", JSON.parse(re.data), this.where, toolbar);
                    }
                    layui.use(['upload','element','layer'], function() {
                        var upload = layui.upload;
                        //执行实例
                        var element = layui.element;
                        var layer = layui.layer;
                        var uploadInst = upload.render({
                            elem: '#SC' //绑定元素
                            ,
                            url: configPro.server_img_interface //上传接口
                            ,
                            done: function (res) {
                                //上传完毕回调
                                alr(res['msg']);
                                $("#SC").parent().html("<img style='width:80%' src='"+res['data']['src']+"'>");
                                debugger;
                                dic.ADD.F_SHOP_IMG =res['data']['src'].replace(/\\/g,"/");
                                element.progress('demo', '0%');
                                layer.closeAll('loading');
                            }
                            ,
                            error: function () {
                                //请求异常回调
                                alr("上传失败！请联系管理员。")
                                element.progress('demo', '0%');
                                layer.closeAll('loading');
                            }
                            ,
                            progress: function (value) {//上传进度回调 value进度值
                                element.progress('demo', value + '%')//设置页面进度条
                            }
                            ,
                            accept: 'file' //普通文件
                            ,
                            xhr: xhrOnProgress
                            ,
                            before: function (obj) {
                                layer.load(); //上传loading
                            }
                        });
                        var uploadInst1 = upload.render({
                            elem: '#SCS' //绑定元素
                            ,
                            url: configPro.server_img_interface //上传接口
                            ,
                            done: function (res) {
                                //上传完毕回调
                                alr(res['msg']);
                                $("#SCS").parent().html("<img style='width:80%' src='"+res['data']['src']+"'>");
                                dic.th.F_SHOP_IMG =res['data']['src'].replace(/\\/g,"/");
                                element.progress('demo', '0%');
                                layer.closeAll('loading');
                            }
                            ,
                            error: function () {
                                //请求异常回调
                                alr("上传失败！请联系管理员。")
                                element.progress('demo', '0%');
                                layer.closeAll('loading');
                            }
                            ,
                            progress: function (value) {//上传进度回调 value进度值
                                element.progress('demo', value + '%')//设置页面进度条
                            }
                            ,
                            accept: 'file' //普通文件
                            ,
                            xhr: xhrOnProgress
                            ,
                            before: function (obj) {
                                layer.load(); //上传loading
                            }
                        });
                    });
                },
                seachs: function () {
                    this.where = whereJSON($(".el-form"));
                    this.loadPage();
                },
                referXadmin: function () {
                    window.location.reload();
                },
                xz_state: function (e) {
                    var e = e.currentTarget;
                    layer.open({
                        type: 2
                        , content: "./vsp?code=1574998957825&token=" + new acquire().parameterMap['token']
                        , area: ["800px", "400px"]
                        , btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            debugger;
                            var body = layer.getChildFrame('body', index);
                            var w = $(layero).find("iframe")[0].contentWindow;
                            var jon = w.checkSure();
                            $(e).val(jon['F_ROLE_NAME']);
                            $(e).attr("uuid", jon['F_ROLE_CODE']);
                            layer.closeAll();
                        }
                        , btn2: function (index, layero) {
                            layer.closeAll();
                        }
                        , cancel: function () {
                            layer.closeAll();
                        }
                    });
                }
            }
        });
        layui.use('form', function () {
            var form = layui.form;
            form.render();
            form.on('submit(formDemo)', function (data) {
                var jon = data.field;
                debugger;
                jon['F_SHOP_IMG']=dic.ADD.F_SHOP_IMG;
                var xe=editor.txt.html();
                xe=xe.replace(/&nbsp;/g," ");
                jon['F_TEXT_IMG']=Base64.encode(xe);
                jon['F_AUTHOR']=dic.User.f_NICKNAME;
                var re = playAjax("1574998957829", jon);
                alr(re['title']);
                if (re['code'] == '0') {
                    setTimeout(function () {
                        dic.referXadmin();
                    }, 500);
                }
                return false;
            });
            form.on('submit(formDemos)', function (data) {
                var jon = data.field;
                debugger;
                jon['F_SHOP_IMG']=dic.th.F_SHOP_IMG;
                jon['uuid']=dic.th.uuid;
                var xe=editor1.txt.html();
                xe=xe.replace(/&nbsp;/g," ");
                jon['F_TEXT_IMG']=Base64.encode(xe);
                jon['F_AUTHOR']=dic.User.f_NICKNAME;
                var re = playAjax("1574998957830", jon);
                alr(re['title']);
                if (re['code'] == '0') {
                    setTimeout(function () {
                        dic.referXadmin();
                    }, 500);
                }
                return false;
            });
        })
    });
    require(['wangEditor'],function (E) {
        editor = new E("#XQ");
        editor.customConfig.uploadImgServer = configPro.server_img_interfacefr; //上传URL
        editor.customConfig.uploadImgMaxSize = 10 * 1024 * 1024;
        editor.customConfig.uploadImgMaxLength = 5;
        editor.customConfig.uploadFileName = 'myFileName';
        editor.customConfig.uploadImgHooks = {
            customInsert: function (insertImg, result, editor) {
                debugger;
                var url =result.data;
                insertImg(url);
            }
        };
        editor.create();




        editor1 = new E("#XQ1");
        editor1.customConfig.uploadImgServer = configPro.server_img_interfacefr; //上传URL
        editor1.customConfig.uploadImgMaxSize = 10 * 1024 * 1024;
        editor1.customConfig.uploadImgMaxLength = 5;
        editor1.customConfig.uploadFileName = 'myFileName';
        editor1.customConfig.uploadImgHooks = {
            customInsert: function (insertImg, result, editor) {
                debugger;
                var url =result.data;
                insertImg(url);
            }
        };
        editor1.create();
    });
});
var xhrOnProgress=function(fun) {
    xhrOnProgress.onprogress = fun; //绑定监听
    //使用闭包实现监听绑
    return function() {
        //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
        var xhr = $.ajaxSettings.xhr();
        //判断监听函数是否为函数
        if (typeof xhrOnProgress.onprogress !== 'function')
            return xhr;
        //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
        if (xhrOnProgress.onprogress && xhr.upload) {
            xhr.upload.onprogress = xhrOnProgress.onprogress;
        }
        return xhr;
    }
}